package com.midea.leetcode;


/**
 * 全排列
 * DFS算法*/
public class TestDfs {
    public static void main(String[] args) {
        //DFS算法,深度优先遍历算法
        //https://blog.csdn.net/weixin_44219085/article/details/105569479
        char[] p = {'A','B','C'};
        boolean[] pb = {false,false,false};
        function(p,pb,new StringBuffer());
    }
    public static void function(char[] p,boolean[] pb,StringBuffer res){
        if (res.length()==p.length){
            System.out.println(res);
            return;
        }
        for (int i = 0;i < p.length;i++){
            char c = p[i];
            if (!pb[i]){
                res.append(c);
                pb[i] = true;
                function(p,pb,res);
                res.deleteCharAt(res.length()-1);
                pb[i] = false;
            }
        }
    }
}
